package com.hd.pzhwlxt.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hd.pzhwlxt.pojo.RepairWoker;
import com.hd.pzhwlxt.service.RepairWokerService;
import com.hd.pzhwlxt.service.StaffBasicInfoService;
import com.hd.pzhwlxt.utils.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @create: 2022-09-21 13:55
 * @author: 怀念天空
 * @Description: 维修工维修记录
 */

//TODO 货物和物资订单，如果发货，库存要减少，还没做。
@RestController
@RequestMapping("/repair")
public class RepairWorkerController {
    @Autowired
    private RepairWokerService repairWokerService;

    @Autowired
    private StaffBasicInfoService staffBasicInfoService;

    /**
     * 查询所有维修工的维修记录，同时返回维修工人员，方便添加维修记录时使用
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/get")
    public Response<Object> getAllRepairWorkerInfo(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize",defaultValue = "15") Integer pageSize){
        // 查询所有的维修记录
        if (pageNum == null || pageSize == null){
            List<RepairWoker> result = repairWokerService.getAllWorkerRepairInfo();
            if(result!=null){
                return Response.createSuccessResponse("查询成功", result);
            }
        }else {
            Page<RepairWoker> result = repairWokerService.getAllWorkerRepairInfoPage(pageNum,pageSize);
            return Response.createSuccessResponse("查询成功", result);
        }
        return Response.createErrorResponse("查询失败");
    }

    /**
     * 添加维修信息，需要车辆编号，耗材费用，工时（通过两个时间相减），维修工，处理人、检出人（部门管理员），原因可以从维修工处获取
     * @return
     */
    @PostMapping("/add")
    public Response<String> addRepairInfo(@RequestBody Object[] requestBody){
        boolean save = repairWokerService.addRepairInfo(requestBody);
        if (save){
            return Response.createSuccessResponse("添加成功");
        }
        return Response.createErrorResponse("添加失败");
    }
}
